package verify

import (
	"awesomeProject/app/request"
	"awesomeProject/app/service"
	"errors"
)

func AccountPagination(r *request.AccountPagination) error {
	if r.PageIndex == 0 {
		r.PageIndex = 1
	}
	if r.PageSize == 0 {
		r.PageSize = 20
	}
	//
	return nil
}

func AccountCreate(r *request.AccountCreate) error {
	if r.Username == "" {
		return errors.New("登录名不能为空！")
	}
	if r.Password == "" {
		return errors.New("密码不能为空！")
	}
	//if len(r.Password) < 6 {
	//	return errors.New("密码不能小于6位！")
	//}
	var accountSrv service.AccountSrv
	_, account := accountSrv.FindByUsername(r.Username)
	if account.ID > 0 {
		return errors.New("账户已经存在！")
	}
	if r.CompanyId == 0 {
		return errors.New("请选择所属组织！")
	}
	if r.Status != nil && !(*r.Status == 0 || *r.Status == 1) {
		return errors.New("状态错误！")
	}

	return nil
}

func AccountUpdate(r *request.AccountUpdate) error {
	if r.Username == "" {
		return errors.New("登录名不能为空！")
	}
	if r.Password == "" {
		return errors.New("密码不能为空！")
	}
	if len(r.Password) < 6 {
		return errors.New("密码不能小于6位！")
	}
	if r.CompanyId == 0 {
		return errors.New("请选择所属组织！")
	}

	if r.Status != nil && !(*r.Status == 0 || *r.Status == 1) {
		return errors.New("状态错误！")
	}

	return nil
}

func AccountGetHashPwd(r *request.AccountGetHashPwd) error {
	if r.OriginPwd == "" {
		return errors.New("密码不能为空！")
	}
	if len(r.OriginPwd) < 6 {
		return errors.New("密码不能小于6位！")
	}

	return nil
}

func AccountGetAccount(r *request.AccountGetAccount) error {
	if r.Username == "" {
		return errors.New("账户名不能为空！")
	}

	return nil
}